<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="70px">
      <el-form-item label="部门名称" prop="bz">
        <el-input v-model="queryParams.bz" placeholder="请输入部门名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="hsr">
         <el-select v-model="queryParams">
          <option :value="item.id" v-for="item,index in [{id:1,name:'正常'},{id:2,name:'异常'}]" :key="index" :label="item.name"></option>
         </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:bzjtable:add']">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
<!-- default-expand-all -->
    <el-table v-loading="loading" height="650" :data="bzjtableList" row-key="id"  :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="编号" align="left" prop="id" width="270"/>
      <el-table-column label="名称" align="center" prop="label" />
      <el-table-column label="上级编号" align="center" prop="upod" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)" v-hasPermi="['system:user:add']">新增下级</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="tit" :visible.sync="open" width="45%" @closed="gb">
      <!-- :rules="ruless" -->
      <el-form ref="forms" :inline="true" :model="form"  label-width="120px" class="creation">
        <el-form-item label="部门名称">
          <el-input v-model="form.mc" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import {getCaseNature,insertCaseNature,updateCaseNature,delectCaseNature} from "@/api/system/bzjtable"
import Print from '@/utils/print.js'
export default {
  name: "Bzjtable",
  data() {
    let dialogVisible = (rule, val, callback) => {
      if (!val) callback(new Error('请输入手机号'))
      let exp = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/)
      if (!exp.test(val)) {
        return callback(new Error('手机号格式不对'))
      }
      return callback()
    }
    let dialogVisible1 = (rule, val, callback) => {
      if (!val) callback(new Error('请输入身份证号'))
      let exp = new RegExp(/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/)
      if (!exp.test(val)) {
        return callback(new Error('身份证号格式不对'))
      }
      return callback()
    }
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      directoryList: [],
      isShow: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      bzjtableList: [],
      // 弹出层标题
      tit: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hsr: null
      },
      // formInfo: {},
      // 表单参数
      form: {
        mc:'',
        lxdh: '',
        sfzh: '',
        mstfr: this.$store.state.user.name,
        mstfsj: this.getNowFormatDate()
      },
      currentIndex: '',
      // 表单校验
      ruless: {
        lxdh: [{ required: true, validator: dialogVisible, trigger: 'change' }],
        sfzh: [{ required: true, validator: dialogVisible1, trigger: 'change' }]
      }
    };
  },
  components: {
    //   selectMultiple,
    //   Upload
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      getCaseNature(this.queryParams).then((res) => {
        console.log("res", res.rows);
        this.bzjtableList =res.rows
      })
      // this.loading = true;
      // forfeitureOfDeposit(this.queryParams).then(response => {
      //   response.rows.forEach((item, index) => {
      //     item.pIndex = index + 1
      //   })
      //   this.bzjtableList = response.rows;
      // this.total = response.total;
      // this.loading = false;
      // });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.getList();
      this.reset();
    },
    selectVal(val) {

    },
    // 表单重置
    reset() {
      this.form = {
        xh: undefined,
        ajbh: undefined,
        ajmc: undefined,
        sqwsh: undefined,
        hsr: undefined,
        xjr: undefined,
        xb: undefined,
        csrq: undefined,
        zz: undefined,
        hjdz: undefined,
        dwzw: undefined,
        lxdh: undefined,
        sfzh: undefined,
        ajxz: undefined,
        sqje: undefined,
        sqfs: undefined,
        sqzt: undefined,
        jkr: undefined,
        jkrsfz: undefined,
        dsyhbh: undefined,
        jnsj: undefined,
        jnkh: undefined,
        pzr: undefined,
        pzsj: undefined,
        bar: undefined,
        dwbh: undefined,
        badw: undefined,
        sqrq: undefined,
        sqtfsj: this.getNowFormatDate(),
        sqtfr: this.$store.state.user.name,
        msje: undefined,
        mszt: undefined,
        msyy: undefined,
        mswsh: undefined,
        mspzr: undefined,
        mspzsj: undefined,
        mstfr: this.$store.state.user.name,
        mstfsj: this.getNowFormatDate(),
        msrq: undefined,
        msshzt: undefined,
        mskhzt: undefined,
        mskhsj: undefined,
        mskhczr: undefined,
        thje: undefined,
        thfs: undefined,
        thzt: undefined,
        thrq: undefined,
        thwsh: undefined,
        thpzr: undefined,
        thtfsj: undefined,
        thshzt: undefined,
        thshr: undefined,
        thshsj: undefined,
        thxm: undefined,
        thzh: undefined,
        thkhh: undefined,
        djzt: undefined,
        sqdyzt: undefined,
        djsj: undefined,
        sqkpzt: undefined,
        thkpzt: undefined,
        hbwsh: undefined,
        hbdw: undefined,
        hbje: undefined,
        hbry: undefined,
        hbrq: undefined,
        hblxdh: undefined,
        hbsj: undefined,
        hbczy: undefined
      };
      this.resetForm("forms");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.hsr = ''
      this.resetForm("queryForm");
      this.handleQuery();
    },
    gb() {
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.xh)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd(e) {
      this.tit = "添加";
      this.reset();
      this.open = true;
      this.form.sjbh = e.id
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log("row",row);
      this.tit = "修改";
      this.open = true;
      this.form.mstfsj = this.getNowFormatDate()
      this.form.mstfr = this.$store.state.user.name
      this.form.mc = row.label
      this.form.bh= row.id
      // this.reset();
      // const XH = row.XH || this.ids
      // updateMsshzt(XH).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      // });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(" this.$refs.forms", this.$refs.forms);
      this.$refs.forms.validate(valid => {
        console.log("va",valid);
        if (valid) {
          if (this.form.bh != null) {
            // if (this.form.files && this.form.files.length) {
            //   this.form.fileFirstPath = this.form.files[0].fj.fileFirstPath
            //   this.form.fileLastPath = this.form.files[0].fj.fileLastPath
            //   this.form.newFileName = this.form.files[0].fj.newFileName
            //   this.form.originalFilename = this.form.files[0].fj.originalFilename
            // }

            updateCaseNature(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.sqzt = 0
            // if (this.form.files.length) {
            //   this.form.fileFirstPath = this.form.files[0].fj.fileFirstPath
            //   this.form.fileLastPath = this.form.files[0].fj.fileLastPath
            //   this.form.newFileName = this.form.files[0].fj.newFileName
            //   this.form.originalFilename = this.form.files[0].fj.originalFilename
            // }
            insertCaseNature(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const XHs = row.XH || this.ids;
      // this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + this.form.xh + '"的数据项？').then(function () {
      //   return delBzjtable(this.form.xh);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => { });

      this.$confirm('是否确认删除编号为"' + row.id + '"的数据项？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delectCaseNature(row.id).then(res => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.isShow = true
      console.log(this.$refs.print);
      this.$nextTick(() => {
        Print(this.$refs.print)
        this.isShow = false
      })
      // this.download('system/bzjtable/export', {...this.queryParams}, `bzjtable_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
@page {
  size: 1220px 880px;
  margin-top: 0mm;
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
.creation {
  .el-form-item {
    margin-bottom: 15px;
  }

  ::v-deep.el-input__inner {
    width: 250px;
  }

  .xx {
    ::v-deep.el-input__inner {
      width: 630px;
    }
  }
}

::v-deep .el-table__body-wrapper::-webkit-srollbar-track {
  background-color: rgba(255, 255, 255, 0);
}

//可设置胶囊宽高
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  height: 12px;
  width: 10px;
  opacity: 0.5;
}

// 设置胶囊色
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 15px;
  background-color: #cdd9e6;
}

.box {
  display: flex;
  justify-content: center;
  padding: 40px;
  height: 800px;

  .heade {
    text-align: center;

    > h4 {
      font-weight: 600;
    }

    > h2 {
      margin: 6px 0 5px 0;
      font-weight: 600;
    }
  }

  .cont {
    margin-top: 30px;

    .line {
      width: 150px;
      height: 20px;
      text-align: right;
      margin-left: 30px;
      border-bottom: 1px solid #000;
    }

    .text {
      text-indent: 24px;
      width: 400px;
      line-height: 40px;
      // margin-top: 50px;
      margin: 20px auto;
    }

    .footer {
      width: 400px;
      margin-top: 50px;
      float: right;
      text-align: center;
    }
  }

  .lf {
    width: 300px;
    border: 1px solid #000;
    margin-right: 50px;
    padding: 6px;
  }

  .lr {
    width: 600px;
    padding: 6px;
    border: 1px solid #000;
  }

  ::v-deep.el-form-item {
    margin-bottom: 0;
  }

  // .noBorder {

  //   ::v-deep.el-input__inner:focus {
  //     box-shadow: 0 0 0 0 !important;
  //   }

  //   ::v-deep.el-input__inner {
  //     border-radius: 0 !important;
  //     border: none !important;
  //     border-bottom: 1px solid #dcdfe6 !important;
  //   }
  // }
}

::v-deep .el-table__body .el-table__row.hover-bg td {
  background-color: #cde6f7 !important;
}
</style>